package device

import (
	"encoding/json"
	"gitee.com/zhanghuamingmyself/api"
	"gitee.com/zhanghuamingmyself/util"
)

var deviceSensorBasePath = "iot/api/v1/v1/device/sensor/"

type IotDeviceSensor struct {
	api.BaseDTO
	Port        string          `json:"port"`
	ValueDate   int32           `json:"valueDate"`
	ExplainList []IotDeviceExplain `json:"explainList"`
	ParamList   []IotDeviceExplain `json:"paramList"`
	SettingList []IotDeviceExplain `json:"settingList"`
}

type IotDeviceSensorListReq struct {
	DeviceCore  string `json:"deviceCore"`
	WithParam   *bool   `json:"withParam"`
	WithSetting *bool   `json:"withSetting"`
	WithExplain *bool   `json:"withExplain"`
}

func ListDeviceSensor(req IotDeviceSensorListReq) ([]IotDeviceSensor, error) {
	var deviceSensorList []IotDeviceSensor
	bytes, err := util.PostJson(deviceSensorBasePath+"list", req)
	if err != nil {
		return deviceSensorList, err
	}
	json.Unmarshal(bytes, &deviceSensorList)
	return deviceSensorList, nil
}
